<?php

namespace app\api\model;

use app\common\enums\StatusEnum;

class TieBaType extends \app\common\model\TieBaType
{
    /**
     * 贴吧板块分类
     * @param bool $joinNum 是否统计参与人数
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function getList($joinNum = false)
    {
        $model = static::field('id, name')
            ->where(['status' => StatusEnum::ENABLED])
            ->order(['sort_num' => 'desc', 'create_time' => 'desc'])
            ->select()
            ->toArray();
        if ($joinNum === true) {
            $num = TieBa::countByTie();
            foreach ($model as $key => $value) {
                $model[$key]['num'] = isset($num[$value['id']]) ? $num[$value['id']] : 0;
            }
        }
        return $model;
    }
}